import React, { Component } from 'react';
import { object, number, func, array } from 'prop-types';
import { Pagination } from 'antd';
import CommentItem from './commentItem';
import NoData from '../common/NoData';
import { ANCHORS } from '../../utils/constant';

export default class Comment extends Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    this.props.getCommentList({ pageNum: 1 });
  }
  onChangePage({ pageNum }) {
    this.props.getCommentList({ pageNum });
    let comment = document.getElementById(ANCHORS[3].href);
    let body = document.body;
    const height = (window.innerWidth * (279 + 80 + 25)) / 1920; // 279footer anchorbar margin
    body.scrollTop = body.scrollHeight - (comment.scrollHeight + height);
  }
  render() {
    const { dataList, totalNum } = this.props;
    return (
      <div>
        {dataList && dataList.length > 0 ? (
          <div>
            <ul>
              {dataList.map((item, index) => (
                <CommentItem item={item} key={item.id} />
              ))}
            </ul>
            <div style={{ textAlign: 'right' }}>
              {' '}
              <Pagination
                defaultCurrent={1}
                total={totalNum}
                onChange={(pageNum, pageSize) => this.onChangePage({ pageNum })}
              />
            </div>{' '}
          </div>
        ) : (
          <div>
            <NoData text="暂无评价" iconClass="icon-nodata-message" />
          </div>
        )}
      </div>
    );
  }
}
